﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AT.IBMS.Framework.Controls
{

    public partial class AspNetPager
    {
        
        /// <summary>
        /// 引发 <see cref="PageChanging" /> 事件。这使您可以为事件提供自定义处理程序。
        /// </summary>
        /// <param name="e">一个包含事件数据 <see cref="PageChangingEventArgs" /> 。</param>
        protected virtual void OnPageChanging(PageChangingEventArgs e)
        {
            //pageChangeEventHandled = true;
            PageChangingEventHandler handler = (PageChangingEventHandler)Events[EventPageChanging];
            if (handler != null)
            {
                handler(this, e);
                if (!e.Cancel || UrlPaging) //there's no way we can obtain the last value of the CurrentPageIndex in UrlPaging mode, so it doesn't make sense to cancel PageChanging event in UrlPaging mode
                {
                    CurrentPageIndex = e.NewPageIndex;
                    OnPageChanged(EventArgs.Empty);
                }
            }
            else
            {
                CurrentPageIndex = e.NewPageIndex;
                OnPageChanged(EventArgs.Empty);
            }
            //pageChangeEventHandled = false;
        }

        /// <summary>
        /// 引发 <see cref="PageChanged" /> 事件。这使您可以为事件提供自定义处理程序。
        /// </summary>
        /// <param name="e">一个包含事件数据 <see cref="System.EventArgs" /> 。</param>
        protected virtual void OnPageChanged(EventArgs e)
        {
            EventHandler handler = (EventHandler)Events[EventPageChanged];
            if (handler != null)
                handler(this, e);
        }

        /// <summary>
        /// 引发<see cref="PageChanging"/>和<see cref="PageChanged"/>事件，跳转到指定页面。
        /// </summary>
        /// <param name="pageIndex">要跳转到的页索引。</param>
        public virtual void GoToPage(int pageIndex)
        {
            OnPageChanging(new PageChangingEventArgs(pageIndex));
        }
    }

}
